    //HttpPrinter 打印工具类
    function HttpPrinter(ip, port, printData) {
        // 保存jQuery引用
        this.$ = $;
        this.printUrl = 'http://' + ip + ':' + port + '/';
        this.msgPost = typeof printData === 'string' ? printData : JSON.stringify(printData);
        this.layer = layer; // 直接使用已加载的layer
        
        // 执行打印操作
        this.print = function() {
            var self = this;
            
            // 先检测打印机连接状态
            this.$.get(
                this.printUrl + '?time=' + new Date().getTime()
            ).then(function() {
                return self._sendPrintRequest();
            }).fail(function() {
                // self._handleConnectionError();
            });
        };
        
        // 发送打印请求（内部方法）
        this._sendPrintRequest = function() {
            var self = this;
            this.$.ajax({
                async: false,
                url: this.printUrl,
                type: "POST",
                contentType: "application/x-www-form-urlencoded",
                dataType: "json",
                xhrFields: { withCredentials: false },
                crossDomain: true,
                data: this.msgPost,
                success: function(data) {
                    if(data.status == "ok") {
                        self._showSuccess();
                    } else {
                       // self._showError("打印失败: " + (data.data || '未知错误'));
                    }
                },
                error: function(xhr) {
                    //self._showError("打印请求失败: " + (xhr.responseText || '连接异常'));
                }
            });
        };
        
        // 处理连接错误（内部方法）
        this._handleConnectionError = function() {
            var self = this;
            this.layer.confirm('连接HttpPrinter失败？', {
                btn: ['下载', '启动试试', '关闭'],
                title: '打印机连接问题'
            }, function(){
                window.open('http://www.httpprinter.com/httpprinter.html', "_blank");
            }, function(){
                window.open('HttpPrinter://hello', "_blank");
            });
        };
        
        // 显示成功提示（内部方法）
        this._showSuccess = function() {
            this.layer.msg('打印任务已发送', { icon: 1, time: 2000 });
        };
        
        // 显示错误提示（内部方法）
        this._showError = function(message) {
            this.layer.alert(message, { icon: 2, title: '打印错误' });
        };
    }